<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./lib/react.development.js"></script>
    <script src="./lib/react-dom.development.js"></script>
    <script src="./lib/babel.min.js"></script>
</head>

<body>
    <div id="root">
        <script type="text/babel">
            const root=ReactDOM.createRoot(document.getElementById("root"));
            // class App extends React.PureComponent {
            //     // constructor(props){    
            //     //     super(props)
            //     //         console.log(props);// {userName: 'zhangsan', age: 22}
            //     //         console.log(this.props)
            //     //         console.log(this.props===props);//true
            //     //     }
            //     render(){
            //         return (
            //             <div>   
            //                 <p>userName:{this.props.userName}</p>
            //                 <p>age:{this.props.age}</p>
            //             </div>
            //         )
            //     }
            // }
            // root.render((
            //     <App userName={'zhangsan'} age={22}/>
            // ))

            // 父子也可以通过属性进行数据的传递
             // 子组件接收到的属性是只读的（不允许修改）
             class App extends React.Component{
                info={
                    userName:'zhangsan',
                    age:22
                }
                render(){
                    return((
                        <div>
                            <h3>App组件</h3>
                            <Child userName={this.info.userName} age={this.info.age}/>
                            {/*以下代码是上方代码的语法糖*/}
                            {/* <Child {...this.info}/> */}
                        </div>
                    ))
                }
            }
            class Child extends React.Component {
                run(){
                    
                   console.log( this.props.userName)
                   console.log( this.props.age)
                }
                render(){
                    return (
                        <div>
                            <button onClick={this.run.bind(this)}>{this.props.userName}</button>    
                            <button onClick={this.run.bind(this)}>{this.props.age}</button>    
                        </div>
                    )
                }
            }
            root.render(<App a={1}/>)
        </script>
</body>

</html>